//加载公共样式
require('../../assets/css/index.less')


let dom = require('../../utils/dom')
const request = require('../../utils/request')

//服务器地址
const API = 'http://fitness.h5.itsource.cn:3701'

//字体图标
require('../../assets/fonts/iconfont.css')
//加载自己的样式
require('./my.less')


window.onload = () => {
    //底部
    dom.Bmenu('my')

    const avatar = document.querySelector('#avatar')
    const nickname = document.querySelector('#nickname')
    const sign = document.querySelector('#sign')
    const clockDay = document.querySelector('#clockDay')
    const dynamicCount = document.querySelector('#dynamicCount')
    const meter = document.querySelector('#meter')
    const calorie = document.querySelector('#calorie')
    const clockBtn = document.querySelector('#clockBtn')
    const sportData = document.querySelector('.sportData')
    const sportBadge = document.querySelector('.sportBadge')

    //是否已打卡
    function isClock() {
        request.get('/api/user/clockInInfo').then(res => {
            console.log(res);
            let { errno, data } = res.data
            if (errno == 0) {
                clockBtn.textContent = data.isClockIn ? '已经打过啦' : '今日打卡'
            }
        })
    }
    isClock()

    function getUserInfo() {
        request.get('/api/user/info').then(res => {
           
            let { data, errno } = res.data
            if (errno == 0) {
                render(data)
            }
        })
    }
    //渲染
    function render(data) {
        
        avatar.src = data.imgUrl
        nickname.textContent = data.nickName
        sign.textContent = data.sign ? data.sign : '无'
        clockDay.textContent = data.clockCount
        dynamicCount.textContent = data.circlesCount
        meter.textContent = data.meter
        calorie.textContent = data.calorie
    }

    getUserInfo()

    sportData.addEventListener('click',function(){
        location.href='./motionData.html'
    })

    sportBadge.addEventListener('click',function(){
        location.href='./mybadge.html'
    })

}